/**
 * Created by zhouxinran on 2017/9/29.
 */

$(function(){
    headerNav("sy");
    $('[data-toggle="popover"]').popover();
    
    /**轮播图**/
    var indexImageListSize = "1";
    if(indexImageListSize >"1"){
        swiperH(3000);
    }else{
        swiperH(false);
    }
    
    /**图片点击效果**/
    var bannerFooterImg = $(".banner-footer-img li"),
        bannerFooterBgContent = $(".banner-footer-bg-content");
    for(i=0;i<bannerFooterImg.length;i++){
        $(bannerFooterImg).eq(i).on("mouseover",function(event){
            event.stopPropagation();
            var thiz = $(this).find(".banner-footer-bg-content");
            $(thiz).slideDown();
        })
        $(bannerFooterImg).on("mouseleave",function(event){
            event.stopPropagation();
            var thiz = $(this).find(".banner-footer-bg-content");
            $(thiz).slideUp();
        });
    }
});
function swiperH(autoplay){
    var swiperH = new Swiper('#swiper-h', {
        autoplay:autoplay,
        speed:600,
        visibilityFullFit : true,
        loop:true,
        pagination: '.swiper-pagination-h'
    });
    $("#swiper-h").find(".swiper-slide").css("height",730);
    if(swiperH.bullets.length === 1){
        $(swiperH.bullets).hide();
        
    }
}
$('.mod-video .item').on('click',function(){
    var $videobox=$(".video-box"),
        htmlFlash='<embed src="http://yuntv.letv.com/bcloud.swf" allowFullScreen="true" quality="high"  width="960" height="500" align="middle" allowScriptAccess="always" flashvars="uu='+$(this).data("src")+'&auto_play=1&gpcflag=1&width=960&height=500" type="application/x-shockwave-flash"></embed>';
    $videobox.html('').html(htmlFlash);
    console.log(htmlFlash)
    $('.playvideo').show();
})


$('.video-cancel').on('click',function(){
    $('.playvideo').hide();
})



/*新闻滚动*/
function scrollUp(){
    var $this = $("#scrollup");
    var scrollTimer;
    $this.hover(function(){
        clearInterval(scrollTimer);
    },function(){
        scrollTimer = setInterval(function(){
            scrollNews( $this );
        }, 5000 );
    }).trigger("mouseleave");
}
function scrollNews(obj){
    var $self = obj.find("ul:first");
    var lineHeight = $self.find("li:first").height(); //获取行高
    $self.animate({ "marginTop" : -lineHeight +"px" }, 1000 , function(){
        $self.css({marginTop:0}).find("li:first").appendTo($self); //appendTo能直接移动元素
    })
}

$(function(){
    
    //新闻滚动
    scrollUp();
    //刷脸APP下载
    /* bannerLeft(); */
    
    $("#j-case ul li").each(function(index){
        $(this).click(function(){
            $("#j-case-bd ul").removeClass("arrow");
            $("#j-case-bd ul").eq(index).addClass("arrow");
        })
    });
    
    var swiper = new Swiper('.swiper-container', {
        autoplay: 3000,
        effect: 'fade'
    });
    
    $('.swiper-container').hover(function() {
        swiper.stopAutoplay();
    }, function() {
        swiper.startAutoplay();
    });
})

var i=0;
$("#j-case ul li").each(function(index){
    $(this).click(function(){
        $("#j-case-bd ul").removeClass("arrow");
        $("#j-case ul li").removeClass("current");
        $("#j-case-bd ul").eq(index).addClass("arrow");
        $("#j-case ul li").eq(index).addClass("current");
        i=index;
    })
})

function autoplay(){
    var len=$("#j-case ul li").length;
    $("#j-case ul li").removeClass("current");
    $("#j-case ul li").eq(i).addClass("current");
    $("#j-case-bd ul").removeClass("arrow");
    $("#j-case-bd ul").eq(i).addClass("arrow");
    if(i++ > len-2){
        i=0;
    }
}
setInterval(autoplay,3000);

    
    function fiexdFooter(){
        var winHeight =  $(window).height();  //浏览器可视高度
        var footerHeight = $('.footer').length>0 ? $('.footer').height():0;	//页脚高度
        var bodyHeight = $("body").css({height:"auto"}).outerHeight(true);		//文档高度
        var spaceHeight = winHeight-footerHeight;
        if(bodyHeight < winHeight){
            $('.footer').offset({top:spaceHeight})
        }
        
    }
    
    $(window).resize(function(){
        fiexdFooter();
    });
    setTimeout(function(){
        fiexdFooter();
    },20);

    


function headerNav(typename){
    $('[data-menuUl="o2owebsite-headerNav"]').children("li").removeClass("o2owebsite-active");
    $('[data-menu="o2owebsite-'+typename+'"]').addClass("o2owebsite-active");
}


